from django.db import models


class AIConfig(models.Model):
    """AI配置模型"""
    name = models.CharField(max_length=100, verbose_name="配置名称")
    api_key = models.CharField(max_length=200, verbose_name="API密钥")
    api_url = models.URLField(verbose_name="API地址", default="https://api.deepseek.com/v1/chat/completions")
    model_name = models.CharField(max_length=100, verbose_name="模型名称", default="deepseek-chat")
    max_tokens = models.IntegerField(default=1000, verbose_name="最大令牌数")
    temperature = models.FloatField(default=0.7, verbose_name="温度参数")
    is_active = models.BooleanField(default=True, verbose_name="是否启用")
    created_at = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    updated_at = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        verbose_name = "AI配置"
        verbose_name_plural = "AI配置"
        ordering = ['-updated_at']

    def __str__(self):
        return self.name


class ChatSession(models.Model):
    """聊天会话模型"""
    session_id = models.CharField(max_length=100, unique=True, verbose_name="会话ID")
    context = models.JSONField(default=list, verbose_name="上下文")
    created_at = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    updated_at = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        verbose_name = "聊天会话"
        verbose_name_plural = "聊天会话"
        ordering = ['-updated_at']

    def __str__(self):
        return self.session_id
